﻿CREATE PROCEDURE [dbo].[InventoryLinesDelete]
(
	@Original_Id int,     --CD.InventoryLines.Id
	@Original_MD datetime --CD.InventoryLines.MD
)
AS
DECLARE @strMsg nvarchar(500), @intRet int, @intErrCode int, @intRowCount int

SET NOCOUNT ON

BEGIN TRAN

EXEC @intRet = dbo.[InventoryLinesTrancDelete] @Original_Id, @Original_MD

IF @intRet <> 0 
BEGIN
	IF @@trancount > 0 ROLLBACK TRAN
	RETURN @intRet
END
	SET NOCOUNT OFF;
--удаляем строку инвентаризации
DELETE FROM CD.InventoryLines WHERE Id = @Original_Id AND MD = @Original_MD
	--SET NOCOUNT ON;
SELECT @intErrCode = @@error, @intRowCount = @@rowcount
IF @intErrCode <> 0 
BEGIN
	IF @@trancount > 0 ROLLBACK TRAN
	RETURN @intErrCode
END
IF (@intRowCount <> 1)
BEGIN
	IF @@trancount > 0 ROLLBACK TRAN
	SELECT @intErrCode = 1, 
	@strMsg = 'Запись из таблицы строк инвентаризации не удалена!'
	RAISERROR (@strMsg, 11, 1)
	RETURN @intErrCode
END

COMMIT TRAN
RETURN 0
